package com.rendevous.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

/**
 * @author Chan See Jiet
 * @version 0.1
 * @since 15-10-2012
 * 
 *        This class contains the common validators for use in other classes.
 * 
 *        Assumptions :-nil-
 * 
 */
public class Validator {
	/**
	 * 
	 * Check for valid command
	 * 
	 * @param command
	 *            -The user's input command
	 * @return true if valid
	 */
	public boolean isValidCommandType(String command) {
		switch (command.toLowerCase()) {
		case Constants.CMD_ADD:
		case Constants.CMD_SHORTCUT_ADD:
			return true;
		case Constants.CMD_REMOVE:
		case Constants.CMD_SHORTCUT_REMOVE:
			return true;
		case Constants.CMD_UPDATE:
		case Constants.CMD_SHORTCUT_UPDATE:
			return true;
		case Constants.CMD_DO:
		case Constants.CMD_SHORTCUT_DO:
			return true;
		case Constants.CMD_HELP:
		case Constants.CMD_SHORTCUT_HELP:
			return true;
		case Constants.CMD_UNDO:
		case Constants.CMD_SHORTCUT_UNDO:
			return true;
		case Constants.CMD_EXIT:
		case Constants.CMD_SHORTCUT_EXIT:
			return true;
		case Constants.CMD_SWITCH:
		case Constants.CMD_SHORTCUT_SWITCH:
			return true;
		case Constants.CMD_LIST_BY_PRIORITY:
			return true;
		case Constants.CMD_LIST_BY_DATE:
			return true;
		case Constants.CMD_LIST:
			return true;
		case Constants.CMD_SEARCH:
			return true;
		default:
			return false;
		}
	}

	/**
	 * 
	 * Check for correct number format
	 * 
	 * @param numberString
	 *            -The number in String
	 * @return true if valid
	 */
	public boolean isCorrectNumberFormat(String numberString) {
		try {
			int number = new Integer(numberString);
			return true;
		} catch (NumberFormatException e) {
			return false;
		}
	}

	/**
	 * 
	 * Check for correct date time format
	 * 
	 * @param dateString
	 *            -The date in String
	 * @return true if valid
	 */
	public boolean isCorrectDateTimeFormat(String dateString) {
		try {
			Date date = new SimpleDateFormat(Constants.DATE_FORMAT)
					.parse(dateString);
			return true;
		} catch (ParseException pe) {
			return false;
		}
	}

	/**
	 * 
	 * Check for correct date time syntax
	 * 
	 * @param startDate
	 * @param endDate
	 * @return true if start date is before end date
	 */
	public boolean isCorrectDateTimeSyntax(Date startDate, Date endDate) {
		if (startDate.before(endDate)) {
			return true;
		} else {
			return false;
		}
	}

	public boolean isValidInputNumber(int listSize, int input) {
		if (input < listSize)
			return true;
		else
			return false;
	}

	/**
	 * 
	 * Check for correct priority string existence
	 * 
	 * @param priorityString
	 * @return true if priority exists
	 */
	public boolean hasValidPriority(String priorityString) {
		switch (priorityString.toLowerCase()) {
		case Constants.PRI_HIGH://fall through commands
		case Constants.PRI_NORMAL:
		case Constants.PRI_LOW:
			return true;
		default:
			return false;
		}
	}
}
